<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('第三方认证')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form class="form-horizontal" id="form-third-edit" th:object="${third}">
        <input name="thirdId" type="hidden" th:field="*{thirdId}"/>
        <h4 class="form-header h4">API授权配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">clientId：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="clientId" type="text" th:field="*{clientId}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">clientSecret：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="clientSecret" type="text" th:field="*{clientSecret}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">是否签名：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input type="checkbox" id="sign" th:checked="${third.sign == 0}">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">是否加密：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input type="checkbox" id="enc" th:checked="${third.enc == 0}">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">加密方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('sys_third_enc')}">
                            <input type="radio" th:id="${dict.dictCode}" name="encType" th:value="${dict.dictValue}"
                                   th:field="*{encType}">
                            <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">第三方认证配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">认证地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="authUrl" type="text" th:field="*{authUrl}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">目标服务地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="serverUrl" type="text" th:field="*{serverUrl}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">token地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="tokenUrl" type="text" th:field="*{tokenUrl}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">用户信息地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="profileUrl" type="text" th:field="*{profileUrl}"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">渲染方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('sys_third_render')}">
                            <input type="radio" th:id="${dict.dictCode}" name="render" th:value="${dict.dictValue}"
                                   th:field="*{render}">
                            <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('sys_third_issue')}">
                            <input type="radio" th:id="${dict.dictCode}" name="issueType" th:value="${dict.dictValue}"
                                   th:field="*{issueType}">
                            <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">当前服务地址：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="curUrl" type="text" th:field="*{curUrl}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发地址(REDIRECT)：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="redirectIssueUrl" type="text" th:field="*{redirectIssueUrl}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发地址(POST_MESSAGE)：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="postMessageIssueUrl" type="text"
                               th:field="*{postMessageIssueUrl}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">签发地址(SOAP)：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="soapIssueUrl" type="text" th:field="*{soapIssueUrl}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">认证方式：</label>
                    <div class="col-sm-8">
                        <select name="authTypeList" class="form-control select2-multiple" multiple
                                th:with="type=${@dict.getType('sys_third_auth_type')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:selected="${third.authTypeList.contains(dict.dictValue)}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">同步回收配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">client_name：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="clientName" type="text" th:field="*{clientName}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">应用Id：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="appId" type="text" th:field="*{appId}"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">应用密钥：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="appSecret" type="text" th:field="*{appSecret}"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">密钥：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="dataKey" type="text" th:field="*{dataKey}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">账号同步权限：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input type="checkbox" id="accountSync" th:checked="${third.accountSync == 0}">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">SSO同步权限：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input type="checkbox" id="ssoSync" th:checked="${third.ssoSync == 0}">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">API认证源配置</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">API密钥：</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="apiKey" type="text" th:field="*{apiKey}"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">加密方式：</label>
                    <div class="col-sm-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('sys_third_enc')}">
                            <input type="radio" th:id="${dict.dictCode + 'api'}" name="apiEnc" th:value="${dict.dictValue}"
                                   th:field="*{apiEnc}">
                            <label th:for="${dict.dictCode + 'api'}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" shiro:hasPermission="system:third:edit" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
<!--        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>取 消-->
<!--        </button>-->
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + "system/third";

    function submitHandler() {
        var data = $("#form-third-edit").serializeArray();
        var sign = $("input[id='sign']").is(':checked') ? 0 : 1;
        var enc = $("input[id='enc']").is(':checked') ? 0 : 1;
        var accountSync = $("input[id='accountSync']").is(':checked') ? 0 : 1;
        var ssoSync = $("input[id='ssoSync']").is(':checked') ? 0 : 1;

        data.push({"name": "sign", "value": sign});
        data.push({"name": "enc", "value": enc});
        data.push({"name": "accountSync", "value": accountSync});
        data.push({"name": "ssoSync", "value": ssoSync});

        $.ajax({
            cache: true,
            type: "POST",
            url: prefix,
            data,
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.modal.msgSuccess(data.msg);
                window.location.reload()
            }
        });
    }

</script>
</body>
</html>